import { Form, InputNumber } from "antd";
import { FilesConfig } from "./config";
import ArrayInput from "./ArrayInput";

interface FilesPanelProps {
    files?: FilesConfig;
    onChange: (files: FilesConfig) => void;
}

export default function FilesPanel(props: FilesPanelProps) {
    return (
        <Form labelCol={{ span: 3 }}>
            <Form.Item label="最大文件大小">
              <InputNumber controls={false} precision={0} value={props.files?.maxSize ?? 1024 * 1024} onChange={value => {
                let files = props.files;
                if (value == null) {
                  if (files !== undefined) {
                    delete files.maxSize;
                    props.onChange(files);
                  }
                } else {
                  if (files == undefined) {
                    files = {};
                  }
                  files.maxSize = value;
                  props.onChange(files);
                }
              }} />
            </Form.Item>
            <Form.Item label="忽略路径">
              <ArrayInput valueList={props.files?.ignore ?? []} onChange={value => {
                let files = props.files;
                if (files == undefined) {
                  files = {};
                }
                files.ignore = value;
                props.onChange(files);
              }} />
            </Form.Item>
          </Form>
    );
}